package de.koller.zero.model;

import de.koller.oceanFramework.util.MIn;
import de.koller.oceanFramework.util.MOut;
import de.koller.zero.ZeroRoot;
import de.koller.zero.arch.ZNode;

public class Player extends ZNode {
	
	public final String name;

	protected Player( String name ) {
		this.name = name;
	}
	
	public static Player create() {
		long nid = ZeroRoot.RND.nextLong();
		String name = "P" + Long.toString( nid, Character.MAX_RADIX );
		
		return new Player( name );
	}

	@Override
	public void generate( ZeroRoot root, Object... references ) {
		super.generate( root, references );
		
		MIn i = new MIn( "./realm/player/" + name + ".data" );
		i.readString( 1 );
		i.close();
	}

	@Override
	protected void update( Object... refernces ) {
		super.update( refernces );
		
		MOut o = new MOut( "./realm/players/" + name + ".data" );
		o.writeString( name );
		o.close();
	}
	
}
